package miiteen.twoexploit.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import miiteen.common.json.JsonUtil;
import miiteen.common.utils.JacksonMapper;
import miiteen.core.result.ResultMessage;
import miiteen.core.result.ResultMessageTool;
import miiteen.data.beans.PageBounds;
import miiteen.hr.pubconfig.CurrentHrInfo;
import miiteen.hr.user.beans.UserUserInfo;
import miiteen.sys.base.controller.BaseAction;
import miiteen.sys.login.bean.UserShiro;
import miiteen.sys.login.utils.LoginUtil;
import miiteen.twoexploit.beans.Instructor;
import miiteen.twoexploit.beans.Regulations;
import miiteen.twoexploit.service.RegulationsService;
import net.sf.json.JSONObject;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Name: lzhg_two_regulations
 * Des: -controller
 * Author: qyp
 * Date: 2021-10-20
 * 兰州海关规章制度
 */
@Api(tags = "兰州海关规章制度")
@RestController
@RequestMapping(value = "/two/regulations")
@CrossOrigin
public class RegulationsController extends BaseAction {

	@Autowired
	private RegulationsService regulationsService;




	@ApiOperation("兰州海关规章制度list")
	@RequestMapping(value = "/selectlist", method = RequestMethod.GET)
	public  ResultMessage<Object>  selectlist(@RequestParam int pageSize, @RequestParam int pageNum,String  title, String   content,Long deptId){

		//获取查询条件
		PageBounds pageBounds = new PageBounds();
		pageBounds.setPageNum(pageNum);
		pageBounds.setPageSize(pageSize);
		Map<String, Object> map = new HashMap<>();
		map.put("title",title);
		map.put("content",content);
		map.put("deptId",deptId);


		List<Regulations> listByMap = regulationsService.findListByMap(map, pageBounds);

		String getpages = regulationsService.getpages(map);


		Map<String, Object> map1 = new HashMap<>();
		map1.put("listByMap",listByMap);
		map1.put("totalCount",getpages);



		if (listByMap != null && listByMap.size() > 0) {
			return ResultMessageTool.Success(String.valueOf(pageBounds.getTotal()), map1);
		} else {
			return ResultMessageTool.Success("0", new ArrayList<>());
		}
	}


	@ApiOperation("详情")
	@RequestMapping(value = "/selectone", method = RequestMethod.GET)
	public  ResultMessage<Object>  selectlist(@RequestParam long    id){
		Regulations regulations = new Regulations();

		//判断id是否有值
		if(id>0){
			regulations = regulationsService.findById(id);
		}

		if (regulations != null ) {
			return ResultMessageTool.Success("查询成功", regulations);
		} else {
			return ResultMessageTool.Error("查询失败");
		}
	}

	
    


}